package com.lebang.service.sys;

import com.lebang.entity.sys.AppNotice;
import com.lebang.mapper.sys.AppNoticeMapper;
import com.lebang.model.Whether;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author hwq
 */
@Service
public class AppNoticeService {
    @Autowired
    private AppNoticeMapper appNoticeMapper;


    public JsonData insert(AppNotice po) {
        po.setHasDeleted(Whether.NO.getDbIndex());
        po.setModifyTime(new Date());
        po.setCreateTime(new Date());
        int init = appNoticeMapper.insertSelective(po);

        if (init > 0) {

            return Callback.success("200", "新增成功", null);
        } else {

            return Callback.fail("403", "新增失败", null);
        }
    }


    public JsonData update(AppNotice po) {
        po.setModifyTime(new Date());
        int init = appNoticeMapper.updateByPrimaryKeySelective(po);
        if (init > 0) {

            return Callback.success("200", "修改成功", null);
        } else {

            return Callback.fail("403", "修改失败", null);
        }
    }


    public AppNotice selectByPrimaryKey(Integer id) {
        return appNoticeMapper.selectByPrimaryKey(id);
    }

    public List<AppNotice> selectParent() {
        return appNoticeMapper.selectParent();
    }

    public List<Map<String, Object>> getAllNotice() {
        return appNoticeMapper.getAllNotice();
    }
}
